﻿// License: https://opensource.org/licenses/MIT
// Create Date : 2018-01-01

using System;

namespace Cat.Core.XLog
{
    /// <summary>
    /// ILogProvider的默认实现
    /// </summary>
    public abstract class LogProviderBase : ILogProvider
    {
        protected virtual string GetLogName(Type type)
        {
            if (type == null) return null;
            //如果是泛型类型，则取非泛型的原类型
            if (type.IsGenericType) type = type.GetGenericTypeDefinition();
            return type.FullName;
        }

        public virtual ILogger GetLogger(Type type)
        {
            string name = GetLogName(type);
            return GetLogger(name);
        }

        public virtual ILogger GetLogger(string name)
        {
            if (string.IsNullOrEmpty(name)) name = "default";
            return GetLoggerCore(name);
        }

        protected abstract ILogger GetLoggerCore(string name);
    }
}
